﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common.Logging;
using WuDada.Core.Generic.Util;
using WuDada.Core.Post.Service;
using WuDada.Core.Member;
using WuDada.Core.Post;
using WuDada.Core.Post.Domain;

public partial class contactus : System.Web.UI.Page
{
    private ILog m_Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    private PostFactory m_PostFactory;
    private IMessageService m_MessageService;
    private HttpHelper m_HttpHelper;
    private WebMailService m_WebMailService;

    protected void Page_Load(object sender, EventArgs e)
    {
        m_PostFactory = new PostFactory();
        m_MessageService = m_PostFactory.GetMessageService();
        m_HttpHelper = new HttpHelper();
        m_WebMailService = new WebMailService();

        if (!IsPostBack)
        {
            ClearUI();
        }
    }

    protected void btnSend_Click(object sender, EventArgs e)
    {
        MessageVO messageVO = new MessageVO();
        UIHelper.FillVO(UpdatePanel1, messageVO);
        messageVO.CreatedDate = DateTime.Now;
        messageVO.CreateIP = m_HttpHelper.GetUserIp(Context);
        messageVO = m_MessageService.CreateMessage(messageVO);

        //發信
        m_WebMailService.SendMail_ToContactor_ByMessage(messageVO);

        ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "js", JavascriptUtil.AlertJS("非常感謝您的意見，已將您的意見送出。"), false);
        ClearUI();
    }

    protected void btnClear_Click(object sender, EventArgs e)
    {
        UIHelper.ClearUI(UpdatePanel1);
    }

    private void ClearUI()
    {
        UIHelper.ClearUI(UpdatePanel1);
    }
}